<template>
	<view>
		<view class="uni-box">
			<uni-title class="h4" type="h4" title="基本信息"></uni-title>

			<uni-forms label-width="100px" label-align="center">
				<uni-forms-item v-for="(item,index) in _data.baseData" :key="index" :label="item.label">
					<view style="height: 100%; display: flex; align-items: center;">
						{{ formData[item.value] }}
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<view class="uni-box">
			<uni-title class="h4" type="h4" title="补充信息"></uni-title>
			<uni-forms label-width="120px" label-align="center">
				<uni-forms-item v-for="(item,index) in _data.supplyData" :key="index" :label="item.label">
					<view style="height: 100%; display: flex; align-items: center;"
						v-if="item.value !== 'validityWarning'">
						{{ formData[item.value] }}
					</view>
					<view style="height: 100%; display: flex; align-items: center;"
						v-if="item.value == 'validityWarning'">
						{{ formData['validityWarning']  ==  99 ? "1年" : formData['validityWarning']  + "月" }}
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		getPostDetail
	} from "./request.js"
	import {
		reactive,
		ref
	} from "vue";

	const formData = ref({})

	const _data = reactive({
		baseData: [{
				label: "药品名称：",
				value: "name",
			},
			{
				label: "生产厂家：",
				value: "manufacturer",
			},
			{
				label: "规格：",
				value: "specification",
			},
			{
				label: "药品类型：",
				value: "category",
			},
			{
				label: "零售价(元)：",
				value: "category",
			},
			{
				label: "默认计量：",
				value: "dosDscr",
			},
			{
				label: "剂型：",
				value: "dosform",
			},
			{
				label: "频率：",
				value: "usedFrqu",
			},
			{
				label: "条形码：",
				value: "barcode",
			},
			{
				label: "批准文号：",
				value: "approvalNumber",
			},
			{
				label: "自定义编码：",
				value: "",
			}
		],
		supplyData: [{
				label: "库存预警：",
				value: "inventoryMin",
			},
			{
				label: "有效库存预警：",
				value: "validityWarning",
			},
			{
				label: "是否基药：",
				value: "isBasicMedicine",
			},
		],
	})


	onLoad((e) => {
		let detailId = e.id
		getPostDetail({
			id: detailId
		}).then((res) => {
			res.data.isBasicMedicine = true ? '是' : '否'
			console.log(res.data.validityWarning);
			formData.value = res.data
		})
	})
</script>

<style lang="scss">
	.uni-box {
		padding-left: 14rpx;
	}

	.uni-forms-item {
		border-bottom: 1rpx solid #ccc;
		margin-bottom: 0;
		padding-bottom: 12rpx;
	}
</style>